package cn.stazxr.component;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.File;
import java.io.IOException;

/**
 * Package: cn.stazxr.component
 * ClassName: ImageView
 * @Author: stazxr
 * @Create: 2023/12/9
 * @Version: v1.0
 **/
public class ImageView extends Component {
    private final Image image;
    public ImageView(String filename) throws IOException {
        File file = new File(filename);
        image = ImageIO.read(file);   //我们可以使用ImageIO类来快速将图片文件读取为Image对象
    }

    @Override
    public void paint(Graphics g) {
        //绘制图片需要提供Image对象
        g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), null);
    }
}
